package com.csnf.mall.server.imp;

import com.csnf.mall.entity.Category;
import com.csnf.mall.mapper.CategoryMapper;
import com.csnf.mall.server.ICategoryServer;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import java.util.Collections;
import java.util.List;

public class CategoryServerImp  implements ICategoryServer {
    CategoryMapper categoryMapper;

    public CategoryServerImp(HttpServlet servlet){
        //初始化 mapper
        ServletContext context = servlet.getServletContext();// servlet 上下文
        SqlSession sqlSession = (SqlSession) context.getAttribute("sqlSession");// 获取 mybatis会话
        categoryMapper = sqlSession.getMapper(CategoryMapper.class);// 去查找xml 然后实例化 mapper
    }

    @Override
    public List<Category> getAllCategory() {
        List<Category> categories = categoryMapper.getCategorys();
        return categories;
    }
}
